package com.itheima.service.impl;

import com.itheima.mapper.UserMemberMapper;
import com.itheima.pojo.Member;
import com.itheima.service.UserMemberService;
import org.apache.commons.codec.digest.DigestUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.Map;

@Service
@Transactional
public class UserMemberServiceImpl implements UserMemberService {
    @Autowired
    private UserMemberMapper userMemberMapper;

    //  用户登录
    public void login(Map map) {
        //判断用户是否是会员 不是自动注册
        String telephone = (String) map.get("telephone");//  获取手机号
        //根据手机号来判断是否是会员
        Member member = userMemberMapper.findByTelephone(telephone);
        if(member==null){
            //自动注册会员
            member = new Member();
            member.setPhoneNumber(telephone);//设置手机号
            member.setRegTime(new Date());//设置注册时间
            userMemberMapper.add(member);
        }

    }


}
